package com.itheima.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
构建cookie的servlet
 */
@WebServlet("/create")
public class CreateCookieServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("当浏览器访问到这个servlet的时候，我们就在这里构建一个cookie");
        //如何构建cookie
        Cookie cookie = new Cookie("username", "jack");
        Cookie cookie1 = new Cookie("job", "小钻风");
        System.out.println("构建出来之后 放到响应头中  就返回给了浏览器  完成了cookie的创建及保存");
        response.addCookie(cookie);
        response.addCookie(cookie1);

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("cookie已经创建好，你自己个在浏览器找吧！！");
    }
}
